<?php
class View_Admin_UserAccount extends View_Admin_Index_Template
{
    public $oTemp;
    
    public function displayUserAccountIndex($oModel)
    {
//    	var_dump($_SESSION);die();
    	//$oModel->setData('display_menu',1);
        $this->initTemplate($oModel);
        if(MODE == "FO"){
            $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/fo_user_account_management_index.html');
            /*$this->oTemp->assign('toobar_cancel', $sCancel);
        	$this->oTemp->parse('main.toobar_cancel');*/
	        $arrayUserAccount = $oModel->getUserAccountByIdFo($_SESSION[admin_id]);
			if($arrayUserAccount->num_rows()>0){
		        $i = 0;
		        while($row = $arrayUserAccount->fetch_row()){
		        	$i ++;
		    		$row['no'] = $i;
		            $row['css'] = "row" . ($i % 2);
		        	$this->oTemp->assign('row', $row);
		        	$this->oTemp->parse('main.rowUserAccount');
		        }
			}else{
				$this->oTemp->parse('main.rowNotExist');
			}
        }else{
            $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/user_account_management_index.html');
            $this->oTemp->assign('toobar_new', '?sMod=user_account_index&sAction=add_new_form');
	        $this->oTemp->parse('main.toobar_new');
	        $this->oTemp->assign('toobar_save',"$('frmUpdateCate').submit();");
	        $this->oTemp->parse('main.toobar_save');
	        
	        $arrayUserAccount = $oModel->listUserAccount();
	        $i = 0;
	        while($row = $arrayUserAccount->fetch_row()){
	        	$i ++;
	    		$row['no'] = $i;
	            $row['css'] = "row" . ($i % 2);
	        	$this->oTemp->assign('row', $row);
	        	$this->oTemp->parse('main.rowUserAccount');
	        }
        }
        
//        $this->oTemp->assign('pageHeding','TOP PAGE');
		
    }
    public function addNewUserAccountForm($oModel){
    	$this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/user_account_mamagement_new.html');
//        $this->oTemp->assign('pageHeding','TOP PAGE');
		$sCancel =  '?sMod=user_account_index';
        $this->oTemp->assign('toobar_save', 'check_user_account_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel', $sCancel);
        $this->oTemp->parse('main.toobar_cancel');
        $this->oTemp->assign('action', 'do_add_new');
        $this->oTemp->parse('action');
        $arr_user = $oModel->getUser();
        $str_select = "";
        while($row = $arr_user->fetch_row()){
        	$str_select = $str_select.'<option value="'.$row[admin_id].'">'.$row[admin_fullname].'</option>';
        }
        $this->oTemp->assign('option', $str_select);
        $this->oTemp->parse('main.select');
    }
 	public function editUserAccountForm($oModel){
    	$this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/user_account_mamagement_new.html');
//        $this->oTemp->assign('pageHeding','TOP PAGE');
		$sCancel =  '?sMod=user_account_index';
        $this->oTemp->assign('toobar_save', 'check_user_account_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel', $sCancel);
        $this->oTemp->parse('main.toobar_cancel');
        $this->oTemp->assign('action', 'do_edit');
        $this->oTemp->parse('action');
        
        $array_packet = $oModel->getUserAccountById($_REQUEST[id]);
        $this->oTemp->assign('row', $array_packet->fields);
//        var_dump($array_packet->fields);
        $oModel_User = new Model_UserAccount();
        $arr_user = $oModel_User->getUser();
        $str_select = "";
        while($row = $arr_user->fetch_row()){
        	$selected = '';
        	$str_select = $str_select.'<option value="'.$row[admin_id].'">'.$row[admin_fullname].'</option>';
        }
        $str_select = $str_select.'<option value="'.$array_packet->fields[user_id].'" selected="selected">'.$array_packet->fields[admin_fullname].'</option>';
        $this->oTemp->assign('option', $str_select);
        $this->oTemp->parse('main.select');
    }
}